/* Copyright (c) 2007 Scott Lembcke
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
 
typedef struct cpCircle{
	cpVect c;
	float r;
	
	cpVect tc;
} cpCircle;

cpCircle *cpCircleAlloc(void);
cpCircle *cpCircleInit(cpCircle *circle, cpVect offset, float radius);
cpCircle *cpCircleNew(cpVect offset, float radius);

void cpCircleDestroy(cpCircle *circle);
void cpCircleFree(cpCircle *circle);

cpBB cpCircleCacheData(cpCircle *circle, cpVect pos, cpVect rot);

typedef struct cpSegment{
	cpVect a, b, n;
	cpVect ta, tb, tn;
} cpSegment;

cpSegment* cpSegmentAlloc(void);
cpSegment* cpSegmentInit(cpSegment *seg, cpVect a, cpVect b);
cpSegment* cpSegmentNew(cpVect a, cpVect b);

void cpSegmentDestroy(cpSegment *seg);
void cpSegmentFree(cpSegment *seg);

cpBB cpSegmentCacheData(cpSegment *segment, cpVect p, cpVect rot);

typedef enum cpShapeType{
	CP_CIRCLE_SHAPE,
	CP_SEGMENT_SHAPE,
	CP_POLY_SHAPE,
	CP_NUM_SHAPES
} cpShapeType;

typedef struct cpShape{
	cpShapeType type;
	union {
		cpCircle *circle;
		cpSegment *segment;
		cpPoly *poly;
		void *ptr;
	} shape;
	
	unsigned long id;
	
	cpBB bb;
	int collision_type;
	void *data;
	
	cpBody *body;
	float e, u;
	cpVect surface_v;
} cpShape;

cpShape *cpShapeAlloc(void);
cpShape *cpShapeInit(cpShape *shape, cpShapeType type, void *shape_obj, cpBody *body);
cpShape *cpShapeNew(cpShapeType type, void *shape_obj, cpBody *body);

void cpShapeDestroy(cpShape *shape);
void cpShapeFree(cpShape *shape);

cpBB cpShapeCacheBB(cpShape *shape);

void cpResetShapeIdCounter(void);
